home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 75 / Mac Magazin CD 75.iso / macware / Red Bird's Quick Scripts / Random Desktop / Random Desktop.as < prev   
Encoding:
Text File  |  2000-05-07  |  2.6 KB  |  48 lines  |  [TEXT/ToyS]

  1. (*
  2. Random Desktop 0.2:  Picks a random desktop pattern and a random desktop picture from any number of pictures in a specified folder.
  3. Copyright (C) 1999-2000 Gordon Worley.
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  8.  
  9. For a copy of the GNU General Public License, visit <http://www.gnu.org/> or write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330, Boston, MA 02111-1307, USA.
  10.  
  11. To contact me, please visit my Web site at <http://www.rbisland.cx/> or e-mail me at <redbird@rbisland.cx>.
  12.  
  13. History:
  14.  
  15. 0.2 - Now uses repeating in randPatt() rather than recursion.  Duh!
  16. 0.1.2 - Added error handling to randPict() so that the script won't just stop if it tries to give Desktop Pictures a nonpicture as a picture
  17. 0.1.1 - Fixed a bug with the random numbers (I had to start from one rather than zero) and stopped rounding, since it turns out that random number returns an integer
  18. 0.1 - Added support for random pictures and created handlers for the two desktop setting operations
  19. 0.0 - Initial release.
  20. *)
  21.  
  22. on run
  23.     randPatt()
  24.     randPict()
  25.     tell application "Desktop Pictures" to quit
  26. end run
  27.  
  28. on randPatt()
  29.     set keep_repeating to true
  30.     repeat while keep_repeating is true
  31.     try
  32.         tell application "Desktop Pictures" to set desktop pattern to (random number from 1 to 128) --128 is the largest possible value for small integer, which is what set desktop picture takes
  33.         set keep_repeating to false
  34.     on error --the random number was out of range
  35.         --pass
  36.     end try
  37.     end repeat
  38. end randPatt
  39.  
  40. on randPict()
  41.     tell application "Finder" to set desktopPictFolder to startup disk's folder "Apple Extras"'s folder "Sample Desktop Pictures" --this can point to any folder with just pictures in it that Desktop Pictures can read
  42.     set desktopPictFolderItems to list folder desktopPictFolder
  43.     try
  44.         tell application "Desktop Pictures" to set desktop picture to alias ((desktopPictFolder as string) & desktopPictFolderItems's item (random number from 1 to (length of desktopPictFolderItems))) positioning centered alignment none
  45.     on error --the file was probably not a picture that Desktop Pictures could read
  46.         --you could tell the user here about what happened, but as long as a picture gets set they probably won't care
  47.     end try
  48. end randPict